package com.zlsy.secondtime.threadcoreknowledge.stopthreads;

/**
 * @author zhouliang
 * @date 2020/5/15 14:07
 * <p>
 * 如果使用stop来停止线程，会导致线程运行到一半的时候突然停止，没办法完成一个基本单位的操作
 * 会造成脏数据。
 */
public class StopThread implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println("连队" + i + "开始领取武器");
            for (int j = 0; j < 10; j++) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("连队:" + i + "，" + j + "号人员领取了武器。");
            }
            System.out.println("连队" + i + "已经领取完毕！");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        StopThread r = new StopThread();
        Thread thread = new Thread(r);
        thread.start();
        Thread.sleep(1000);

        thread.stop();
    }
}
